﻿@{
    ViewBag.Title = "Form";
    Layout = "~/Views/Shared/_Form.cshtml";
}
<script>
    var keyValue = $.request("keyValue");
    var successdata = [];
    //var formId = $.request("formId");

    //function find_checkbox(success, error) {
    //    var $gridList = this;
    //    var checkboxs = $gridList.find("input[type='checkbox']:checked"),
    //        selectedVals = [];
    //    if (checkboxs.length) {
    //        checkboxs.each(function (n, ele) { selectedVals.push(ele.value); });
    //        success && success(selectedVals);
    //    } else {
    //        error && error();
    //    }
    //}

    //function valid_checkbox() {
    //    var args = Array.prototype.slice.call(arguments);
    //    if (args.length == 1) {
    //        args.push(function () {
    //            $.modalAlert("请选择相关的订单项", "success");
    //        });
    //    }
    //    find_checkbox.apply(this, args)
    //}

    $(function () {
        $.ajax({
            url: "/OrderFlowManage/ClientOrder/GetOrderRecommendList?orderId=" + keyValue,
            data: { orderId: keyValue },
            dataType: "json",
            async: false,
            success: function (data) {
                console.log(data);
                var $previewTakelookGrid = $('#previewTakelookGrid');
                var html = [],
                    first = '',
                    allState = ["未审核", "通过", "驳回"],
                    allStateColor = ["<button class='btn btn-xs btn-default' type='button' disabled>", "<button class='btn btn-xs btn-success' type='button' disabled>", "<button class='btn btn-xs btn-danger' type='button' disabled>"];
                if (data && data.rows.length) {
                    for (var i = 0; i < data.rows.length; i++) {
                        var item = data.rows[i];
                        html.push("<tr><td>");
                        html.push(item.F_OrderId);
                        html.push("</td><td>");
                        if (first != item.F_No) {
                            html.push(item.F_No);
                            first = item.F_No;
                        }
                        html.push("</td><td>");
                        html.push(item.F_Title);
                        html.push("</td><td>");
                        html.push(item.F_SpaceTitle);
                        html.push("</td><td>");
                        html.push(item.F_CreatorTime);
                        html.push("</td><td>");
                        html.push(allStateColor[item.F_State || 0]);
                        html.push(allState[item.F_State || 0]);
                        html.push("</button>");
                        html.push("</td><td>");
                        html.push(item.F_Remark);
                        html.push("</td></tr>");
                        if (item.F_State == 1) {
                            successdata.push(item);
                        }
                    }
                } else {
                    html.push("<tr><td  colspan='5' style='color: red'>没有相关的数据</td></tr>");
                }
                $previewTakelookGrid.html(html.join(''));
            }
        });
    });

    function submitForm() {
        //var $previewTakelookGrid = $('#previewTakelookGrid');
        //var trs = $previewTakelookGrid.find('tr');

        //valid_checkbox.call($previewTakelookGrid, function (cks) {
        //    $.submitForm({
        //        url: "/OrderFlowManage/ClientOrder/SubmitTakelookForm?keyValue=" + orderId,
        //        param: {
        //            orderId: orderId,
        //            flowFormId: formId,
        //            siteIds: cks
        //        },
        //        success: function () {
        //            //$.currentWindow().vm.takkelook.initTakelook();
        //            $.currentWindow().$("#btn_takelook").prop("disabled", true);

        //            $.loading(false);
        //        }
        //    });
        //});
        if (successdata.length) {
            $.submitForm({
                url: "/OrderFlowManage/ClientOrder/SubmitSendSiteFlowForm?keyValue=" + keyValue,
                param: {},
                success: function (data) {
                    // 跳转下一个场地页面
                    $.currentWindow().reloadPage(2);
                    $.loading(false);
                }
            });
        } else {
            $.modalAlert("您没有审批通过的场地！", "warning");
        }
        
    }
</script>

<form id="form1">
    <div style="margin:0 20px;">
        <table class="table table-condensed table-bordered">
            <thead>
                <tr>
                    <td>订单号</td>
                    <td>批次号</td>
                    <td>场地名称</td>
                    <td>空间名称</td>
                    <td>推荐时间</td>
                    <td>状态</td>
                    <td>备注</td>
                </tr>
            </thead>
            <tbody id="previewTakelookGrid"></tbody>
        </table>
    </div>
</form>


